package top.jiangqiang.qianyi.common.convert;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.boot.convert.ApplicationConversionService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.ConversionService;
import org.springframework.format.support.DefaultFormattingConversionService;
import org.springframework.format.support.FormattingConversionService;

@Configuration
@Slf4j
@RequiredArgsConstructor
public class ConverterConfig {

    /**
     * Without spring-boot-starter-web, no custom mappers will be added automatically; Therefore we
     * register all our {@link org.springframework.core.convert.converter.Converter Converters}
     * manually.
     */
    @Bean
    public ConversionService conversionService(final ListableBeanFactory beanFactory) {
        log.info("ConversionService bean init");
        final FormattingConversionService conversionService = new DefaultFormattingConversionService();
        ApplicationConversionService.addBeans(conversionService, beanFactory);
        return conversionService;
    }

}
